<template>
  <uni-nav-bar title="我的车队" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="package">
    <view class="space-between">
      <view>车队名称</view>
      <view>{{TeamInfo.fleetAll.name}}</view>
    </view>
    <view class="space-between top">
      <view>管理员</view>
      <view>{{TeamInfo.fleetAll.nickname}}</view>
    </view>
    <view class="space-between top">
      <view>手机号</view>
      <view>{{TeamInfo.fleetAll.mobile}}</view>
    </view>
    <view class="space-between top">
      <view>累计充值</view>
      <view>{{TeamInfo.fleetAll.total_money}}元</view>
    </view>
    <view class="space-between top">
      <view>账户余额</view>
      <view>{{TeamInfo.fleetAll.money}}元</view>
    </view>
    <view class="space-between top">
      <view>司机价</view>
      <view>{{TeamInfo.fleetAll.price}}元/公斤</view>
    </view>
    <view class="space-between top">
      <view>地推人员</view>
      <view>
        <text v-if="TeamInfo.fleetAll.zhitui_name">{{TeamInfo.fleetAll.zhitui_name}}</text>
        <uni-icons type="forward" size="25" color="#666" @click="navTo('administrator/fleet/addDriver?type=sale')"
          v-else></uni-icons>
      </view>
    </view>
  </view>
  <view class="space-between list">
    <view v-for="item in list" :key='item.name' @click="jump(item.push)">{{item.name}}</view>
  </view>
  <!-- 填写司机价 -->
  <Price @submit="submit" ref="AddPrice"></Price>
</template>

<script setup lang="ts">
  import Price from '@c/administrator/BulletBox/price.vue';
  import { navBack, navTo } from '@/utils/navigator';
  import { onLoad } from '@dcloudio/uni-app';
  import { ref } from 'vue';
  import { showLoading, errorToast, successToast } from '@/utils/prompt';
  import { toPublish } from '@mqtt';
  import { information } from '@/stores/administrator';
  const TeamInfo = information();
  const list = [{ name: '车队成员', push: 'administrator/fleet/memberList' },
  { name: '加注机', push: 'administrator/fleet/fleetFill' },
  { name: '变动明细', push: 'administrator/fleet/changeDetails' },
  { name: '司机价', push: '' },]
  const fleetID = ref()
  const AddPrice = ref(null)
  onLoad((pearm) => {
    fleetID.value = pearm.id
    TeamInfo.geFleetIn(pearm.id)
  })
  // 填写司机价
  function submit(num : number) {
    showLoading()
    const payload = {
      price: num,
      fleet_id: Number(TeamInfo.fleetAll.id)
    };
    toPublish(
      'control/editFleetPrice',
      payload,
      (obj : any) => {
        const { code, msg } = obj;
        if (code === 1) {
          TeamInfo.geFleetIn(TeamInfo.fleetAll.id)
          successToast(msg)
        } else {
          errorToast(msg)
        }
      }
    );
  }
  function jump(push : string) {
    if (push) {
      navTo(push)
    } else {
      AddPrice.value.openBankPad()
    }
  }
</script>

<style scoped lang="less">
  .top {
    margin-top: 15rpx;
  }

  .list {
    width: 96%;
    margin: 15rpx auto;
    flex-wrap: wrap;

    view {
      width: 48.5%;
      height: 102rpx;
      background: #FFFFFF;
      border: 1px solid #EEF3F7;
      border-radius: 6px;
      text-align: center;
      line-height: 102rpx;
      margin-bottom: 15rpx;
    }
  }
</style>